package com.xuelang.pipeline.client.task.enums;

import lombok.Getter;

import java.util.HashMap;
import java.util.Map;

/**
 * <p>任务实例编码枚举</p>
 *
 * @author : yixin.lys
 * @date : 2024-08-26 15:28
 **/
@Getter
public enum TaskInstanceCodeEnum {

    CODE_SOURCE("code_source"),
    JAVA_BUILD("java_build"),
    NODEJS_BUILD("nodejs_build"),
    CUSTOM_IMAGE("custom_image"),
    GO_IMAGE("go_image"),
    JAVA_IMAGE("kaniko-java-pod"),
    PYTHON_IMAGE("python_image"),
    NODEJS_IMAGE("kaniko-npm-pod"),
    JAVA_SCAN("java_scan"),
    GO_SCAN("go_scan"),
    PYTHON_SCAN("python_scan"),
    NODEJS_SCAN("nodejs_scan"),
    PERSON_SCAN("person_scan"),
    SCROLL_DEPLOY("scroll_deploy"),
    GRAY_DEPLOY("gray_deploy"),
    PROVE("prove"),
    GENERAL_DEPLOY("general_deploy");

    private String value;

    TaskInstanceCodeEnum(String value) {
        this.value = value;
    }

    // 创建一个静态映射，将字符串值映射到对应的枚举
    private static final Map<String, TaskInstanceCodeEnum> VALUE_MAP = new HashMap<>();

    // 静态初始化块，将所有枚举值放入映射中
    static {
        for (TaskInstanceCodeEnum operation : TaskInstanceCodeEnum.values()) {
            VALUE_MAP.put(operation.getValue(), operation);
        }
    }

    // 静态方法，将字符串值转换为对应的枚举
    public static TaskInstanceCodeEnum fromValue(String value) {
        TaskInstanceCodeEnum operation = VALUE_MAP.get(value);
        if (operation == null) {
            throw new IllegalArgumentException("未知的操作类型: " + value);
        }
        return operation;
    }

}
